


interface Listener {
    // your code
    (...args:any[]):void;
  } 
  interface Events {
    // your code
    [msg:string]:Listener[]
  }
  
  class EventEmitter {
    // your code 定义私有属性 events
     private events:Events={}
  
    on (eventName: string, listener: Listener) {//收集函数

     if(!this.events[eventName]){
        //第一次
         this.events[eventName]=[listener]
     }else{
         this.events[eventName].push(listener)
     }
      // your code
    }
  
    emit (eventName: string, ...args: any[]) {
      // your code
      this.events[eventName]&&this.events[eventName].map(event=>event(args))

    }
  
    off (eventName: string, listener: Listener) {
      // your code
    }
  
    once (eventName: string, listener: Listener) {
      // your code
    }
  
  }
  
  // 调用示例
  const req = new EventEmitter()
  
  const handler = () => {
    console.log('hello world')
  }
  
  req.on('data', handler)
  
//   req.once('data', handler)
  
  // req.off('data', handler)
  
  req.emit('data')
  req.emit('data')
  